﻿<html>
<head>
<link href="css/qam.css" rel="stylesheet" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<style>
#group_box{display:inline-block;}
.span_aequilate{display:inline-block;width:50px;text-align:right;color:#AF6AAF}
</style>
</head>
<body>

	<div style="width:960px;margin:0 auto">
		<div id="message" ></div>
		
		<HR><h3>类目类型管理</h3>
		<div style="padding:10px;background:#E8E8FF;margin-top:10px;">
			<form method="post" action="#" name="myform" class="myform">
				<input type="hidden" value="" name="id" />
				<label><span>名称：</span><input type="text" value="" name="name" /></label><BR />
				<label><span>描述：</span><input type="text" value="" name="info" /></label><BR />
				<label><span>效果图：</span><input type="hidden" value="" name="img" /><input type="file" id="file" size="10" multiple="true" onchange="select_img(this.files)" /></label><BR />
				<label><span>html路径</span><input type="text" value="" name="html" /></label><BR />
				<label><span>css路径</span><input type="text" value="" name="css" /></label><BR />
				<label><span>js路径</span><input type="text" value="" name="js" /></label><BR />
				<label><span>碎图路径</span><input type="text" value="" name="slice" /></label><BR />
				<label><span>效果图路径</span><input type="text" value="" name="sample" /></label><BR />
				<input type="button" value="添加" onclick="add();" name="button"  />
			</form>
		</div>
		
		<div style="padding:10px;background:#E8E8FF;margin-top:10px;" id="listbox"></div>
		

	</div>



</body>

<script src="js/ajax.js" type="text/javascript"></script>
<script src="js/function.js" type="text/javascript"></script>
<script>



function init(){showlist();}

//html5 选择文件
function select_img(myFiles) {
  for (var i = 0, f; f = myFiles[i]; i++) {
    var imageReader = new FileReader();
    imageReader.onload = (function(aFile) {
      return function(e) {
        document.myform.img.value=e.target.result;
		//document.getElementById('src_present').value=$$("src_file").files[0].name;
      };
	  
    })(f);
    imageReader.readAsDataURL(f);
  }
}


/*****project_type add********/
function add(){
	var _url=cgipath+"project-typeAdd";
	var ajax_obj=new AJAX_OBJ(_url,handle_add,handle_error,5000);
	ajax_obj.postData(formToString(document.myform));
}
function handle_add(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	$$("message").innerHTML="【ret】"+ret_json.ret+"【msg】"+ret_json.msg;
	showlist();
}
/*****project_type getinfo********/
function edit(t){
	var _url=cgipath+"project-typeGetinfo";
	var ajax_obj=new AJAX_OBJ(_url,handle_edit,handle_error,5000);
	ajax_obj.postData("&id="+t);
}
function handle_edit(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	$$("message").innerHTML="【ret】"+ret_json.ret+"【msg】"+ret_json.msg;
	document.myform.id.value=ret_json.record.id;
	document.myform.name.value=ret_json.record.name;
	document.myform.info.value=ret_json.record.info;
	document.myform.img.value=ret_json.record.img;
	document.myform.html.value=ret_json.record.html;
	document.myform.css.value=ret_json.record.css;
	document.myform.js.value=ret_json.record.js;
	document.myform.slice.value=ret_json.record.slice;
	document.myform.sample.value=ret_json.record.sample;
	document.myform.button.value="修改";
	document.myform.button.onclick=Function("update("+ret_json.record.id+")");
}

/*****project_type update********/
function update(){
	var _url=cgipath+"project-typeUpdate";
	var ajax_obj=new AJAX_OBJ(_url,handle_update,handle_error,5000);
	ajax_obj.postData(formToString(document.myform));

}
function handle_update(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	$$("message").innerHTML="【ret】"+ret_json.ret+"【msg】"+ret_json.msg;
	showlist();
}


/*****project_type del********/

function del(t){
	var _url=cgipath+"project-typeDel";
	var ajax_obj=new AJAX_OBJ(_url,handle_del,handle_error,5000);
	ajax_obj.postData("&id="+t);
}
function handle_del(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	$$("message").innerHTML="【ret】"+ret_json.ret+"【msg】"+ret_json.msg;
	showlist();
}

/*****project_type list********/
var page=1;//第1页
var reqnum=10;//每页显示10条
var order="id";//排序字段
var desc="1";//反序,0或空正常排序，1反序
var page_nums=0;

function showlist(){

	var _url=cgipath+"project-typeShowlist";
	var ajax_obj=new AJAX_OBJ(_url,handle_showlist,handle_error,5000);
	ajax_obj.postData("&page="+page+"&reqnum="+reqnum+"&order="+order+"&desc="+desc);
}

function handle_showlist(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	var str="<table><thead><tr>";
	str+="<td><a href='javascript:order=\"id\";desc=bin_exchange(desc);list_page(0)'>序号</a></td>";
	str+="<td><a href='javascript:order=\"name\";desc=bin_exchange(desc);list_page(0)'>名称</a></td>";
	str+="<td>简介</td>";
	str+="<td>预览图</td>";
	str+="<td>结构</td>";
	str+="<td>操作</td></tr></thead>";
	page_nums=Math.ceil(ret_json.nums/reqnum);
	for(var i=0;i<ret_json.listdata.length;i++){
		str+="<tr><td>"+((page-1)*reqnum+i+1)+"</td>";
		str+="<td>"+ret_json.listdata[i].name+"</td>";
		str+="<td>"+ret_json.listdata[i].info+"</td>";
		var str_img="";
		if(ret_json.listdata[i].img!="")str_img="<img src=\""+cgipath+ret_json.listdata[i].img+"\" />";
		str+="<td>"+str_img+"</td>";
		var str2="<span class=\"span_aequilate\">html：</span>"+ret_json.listdata[i].html;
		str2+="<BR><span class=\"span_aequilate\">css：</span>"+ret_json.listdata[i].css;
		str2+="<BR><span class=\"span_aequilate\">js：</span>"+ret_json.listdata[i].js;
		str2+="<BR><span class=\"span_aequilate\">碎图：</span>"+ret_json.listdata[i].slice;
		str2+="<BR><span class=\"span_aequilate\">预览图：</span>"+ret_json.listdata[i].sample;
		str+="<td>"+str2+"</td>";
		str+="<td><a href='#' onclick='edit("+ret_json.listdata[i].id+")'>修改</a><a href='#' onclick='del("+ret_json.listdata[i].id+")'>删除</a></td></tr>";
	}
	str+="<tr><td colspan=5>共"+ret_json.nums+"条，每页"+reqnum+"条，"+page+"/"+page_nums+"</td>";
	str+="<td><a href='#' onclick='list_page(-1)'>上一页</a><a href='#' onclick='list_page(1)'>下一页</a></td></tr>";
	str+="</table>";
	$$("listbox").innerHTML=str
}

/*列表翻页*/
function list_page(t){
	page=page-(-1)*t;
	if(page<=0)page=1;
	else if(page>page_nums) page=page_nums;
	showlist();
}

</script>
<script src="js/public.js" type="text/javascript"></script>


</html>